﻿using AutoMapper;
using MediatR;
using MyMES.Domain.zmc;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Writer.API.Application.Commends.Incominginformations;

namespace MyMES.Writer.API.Application.CommendHandlers.Incominginformations
{
    public class UpdataIncominginformationsCommendHandlers : IRequestHandler<UpdataIncominginformationsCommends, APIResult<Incominginformation>>
    {
        private readonly IBaseRepository<Incominginformation> baseRepository;
        private readonly IMapper mapper;

        public UpdataIncominginformationsCommendHandlers(IBaseRepository<Incominginformation> baseRepository, IMapper mapper)
        {
            this.baseRepository = baseRepository;
            this.mapper = mapper;
        }


        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<Incominginformation>> Handle(UpdataIncominginformationsCommends request, CancellationToken cancellationToken)
        {
            APIResult<Incominginformation> result = new APIResult<Incominginformation>();
            result.Code = APIEnum.修改成功;
            result.Msg = "修改成功";
            var customer = mapper.Map<Incominginformation>(request);
            string sql = "UPDATE incominginformation SET StorageId=@StorageId,StorageNo=@StorageNo,StorageName=@StorageName,noticeId=@noticeId,SupplierId=@SupplierId,Storageremark=@Storageremark,StoragePurchaseId=@StoragePurchaseId,StorageDate=@StorageDate,IsDlete=@IsDlete where StorageId=@StorageId";
            await baseRepository.Update(customer, sql);
            return result;
        }
    }
}
